import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default ({ mode } : { mode: any }) => defineConfig({
	//移除生产环境log
	plugins: [vue()],
	resolve: {
		alias: {
			'@': fileURLToPath(new URL('./src', import.meta.url)),
			'views': fileURLToPath(new URL('./src/Views', import.meta.url)),
		}
	},
	css: {
		preprocessorOptions: {
			// 全局变量引入
			scss: {
				additionalData: '@import "./src/Assets/Css/default.scss";',
				javascriptEnabled: true
			}
		}
	},
	// build: {
	// 	rollupOptions: {
	// 		manualChunks: {
	// 			'Form': ['form'],
	// 			'FormComponent': ['form-component']
	// 		}
	// 	}
	// },
	build: {
		// minify: 'terser',
		terserOptions: {
			compress: {
				//生产环境时移除console
				drop_console: true,
				drop_debugger: true,
			},
		},
		chunkSizeWarningLimit: 1000,
		rollupOptions: {
			output: {
				manualChunks: id => {
					if (id.indexOf('echarts') > -1) {
						return 'echarts';
					}
					if (id.indexOf('wangeditor') > -1) {
						return 'wangeditor';
					}
				},
			}
		}
	},
	define: {
		'process.env': loadEnv(mode, process.cwd())
	},
	server: {
		host: "localhost",
		port: 5175,
		proxy: {
			'/dev': {
				target: 'http://8.129.10.102:8080',
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/dev/, '')
			}
		}
	}
});
